﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Beaker50ml : BaseBrokenObj
{
    public Animator m_WaterAnimator;
    public GameObject m_Water;
    public BeakerBrush m_BeakerBrush;

    [HideInInspector]
    public bool CanClear;

    public override void OnHandleTrigger(Transform camera, NoloDeviceType handleType)
    {
        base.OnHandleTrigger(camera, handleType);
        m_WaterAnimator.SetBool("take", true);
    }

    public override void OnReleseTrigger(NoloDeviceType handleType)
    {
        base.OnReleseTrigger(handleType);
        m_WaterAnimator.SetBool("take", false);
    }

    Vector3 towardPos;
    Vector3 lastPos;
    float speed;

    private void LateUpdate()
    {
        towardPos = transform.position - lastPos; //两帧间向量差  
        speed = towardPos.magnitude / Time.deltaTime; // 距离/时间 
        lastPos = transform.position; //设置lastPosition
        m_WaterAnimator.SetFloat("speed", speed);
    }

    private void Update()
    {
        if (m_BeakerBrush.isCatch && isCatch && CanClear)
        {
            if ((m_BeakerBrush.transform.position.x < transform.position.x
            && (m_BeakerBrush.transform.position - transform.position).magnitude < 0.1f)
            || (m_BeakerBrush.transform.position.x > transform.position.x
            && (m_BeakerBrush.transform.position - transform.position).magnitude < 0.3f))
            {
                transform.eulerAngles = new Vector3(0, 0, -90);
                m_BeakerBrush.SetScale(transform.position);
            }
        }
    }

    int ClearNum;
    private void OnTriggerEnter(Collider other)
    {
        if (other.name == "BeakerBrush")
        {
            if (StepsManager.Instance.StepFourNum[1])
            {
                if (!StepsManager.Instance.StepFiveNum[1])
                {
                    ClearNum++;
                    if (ClearNum == 2)
                    {
                        StepsManager.Instance.StepFiveNum[1] = true;
                        StepsManager.Instance.SetStepFive(1);
                    }
                }
            }
        }

    }
}
